#ifndef __chain_trochoid__
#define __chain_trochoid__

//define some values to variable array
//Dc = 0
//Vc = 1
//Zc = 2
//Fz = 3


if(token.Matches(_("p_trochoid"))&&(T.GetCount()==5))
{
    IsNotExtFunc = false;

    uint CN = uint(calc(T[0]));   //Chain Number..
    if(C[CN].Size()==0){ERR << _("chain error in p_trochoid");break;}

    double L = C[CN].P1(0).GetDistanceXY(C[CN].P2(0));
    double D = C[CN].P1(0).GetDirectionXY(C[CN].P2(0));         //Direction from chain
    double Dc = V[0]/2;                                         //from variable

    double R = calc(T[1]);
    double Z = calc(T[2]);
    double W = calc(T[3]);
    double Ae = calc(T[4]);


    mChain chain;
    chain.Clear();

    Ae = (W-sqrt((W*W)-((Ae*((W-(Dc*2))*4.0)))))/2;

    double n = cd_rpm( V[1] , Dc *2);
    double F = (W-(Dc*2))*n*V[2]*V[3]/W;

    double x=-W/2-Dc+Ae,start_x=-2;

    W=W/2-Dc;
    if(W<1)
    {
         ERR << _("trochoid too small Width\n");
         break;
    }

    chain.Add( cP( mP(x,-W),mP(NAN,NAN,NAN) ,1 ));
    while(x<L)
    {
        x=x+Ae;
        if(x>L)break;
        chain.Add( cP( mP(x,-W,Z),mP(x,0,Z) ,173 ));
        chain.Add( cP( mP(x,-W,Z),mP(0,0,Z) , 1 ));
    }

    x=L;
    chain.Add( cP( mP(x,-W,Z),mP(x,0,Z) ,173 ));
    chain.Add( cP( mP(x,W,Z),mP(0,0,Z) , 1 ));
    chain.Add( cP( mP(start_x,W,Z),mP(0,0,Z) , 1 ));

    //MOVE
    chain.RotateZ(D);
    chain.Translate(mP(C[CN].P1(0).x , C[CN].P1(0).y ,0));

    CODE << chain.CTG(R,Z);
    chain.Clear();
    continue;
}
#endif
